1
1
.
.
4
4
.
.
1
1
j
j
a
a
v
v
a
a
c
c
.
.
e
e
x
x
e
e
I
I
n
n
f
f
o
o
javac.exe is application used to compile java source code files .java into intermediate code files .class.
Examples
COMMAND
DESCRIPTION
javac Test.java
Compile Test.java from current dir and save Test.class in the same dir.
javac *.java
Compile all files with .java suffix from current dir and save their .class files in the same dir.
R
R
e
e
f
f
e
e
r
r
e
e
n
n
c
c
e
e
j
j
a
a
v
v
a
a
c
c
.
.
e
e
x
x
e
e
When referencing javac.exe PATH Environment Variable will be used to locate it if full path is not given.
Examples
COMMAND
DESCRIPTION
javac Test
PATH Environment Variable will be used to locate javac.exe
C:\Install\JDK14\bin\javac Test
Specify full path to javac.exe (PATH Environment Variable is ignored)
-
-
v
v
e
e
r
r
s
s
i
i
o
o
n
n
Displays JAVA version.
Examples
COMMAND
DESCRIPTION
java -version
Display version of java.exe
output
java version "1.5.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-b64)
Java HotSpot(TM) Client VM (build 1.5.0-b64, mixed mode)
-
-
h
h
e
e
l
l
p
p
Displays possible parameters and their usage.
Examples
COMMAND
DESCRIPTION
java -help
Display possible parameters of java.exe
output
Usage: javac <options> <source files>
where possible options include:
-g Generate all debugging info
-g:none Generate no debugging info
-g:{lines,vars,source} Generate only some debugging info
-nowarn Generate no warnings
-verbose Output messages about what the compiler is doing
-deprecation Output source locations where deprecated APIs are used
-classpath <path> Specify where to find user class files
-cp <path> Specify where to find user class files
-sourcepath <path> Specify where to find input source files
-bootclasspath <path> Override location of bootstrap class files
-extdirs <dirs> Override location of installed extensions
-endorseddirs <dirs> Override location of endorsed standards path
-d <directory> Specify where to place generated class files
-encoding <encoding> Specify character encoding used by source files
-source <release> Provide source compatibility with specified release
-target <release> Generate class files for specific VM version
-version Version information
-help Print a synopsis of standard options
-X Print a synopsis of nonstandard options
-J<flag> Pass <flag> directly to the runtime system
-
-
c
c
l
l
a
a
s
s
s
s
p
p
a
a
t
t
h
h
,
,
-
-
c
c
p
p
Defines where to look for class files needed to compile target source file.
You can define directories, JAR or ZIP files.
Examples
COMMAND
DESCRIPTION
javac -classpath classes Test2.java
Look for class files in classes dir in current directory.
javac -classpath .;..\classes;C:\stuff Test2.java
Look for class files in listed directories.
javac -cp servlet.jar;C:\util.zip Test2.java
Look for class files in listed JAR and ZIP files.
-
-
s
s
o
o
u
u
r
r
c
c
e
e
p
p
a
a
t
t
h
h
Defines where to find other source files .java needed to compile target source file.
You can define directories, JAR or ZIP files.
Needed source files are also compiled and their .class files are saved in the same directory where they were found.
You can use it when making changes to multiple .java Classes in different directories so that javac.exe picks them all up
and recreates .class files needed to run your application.
On the other hand your code changes were
only in one class you can simply use Test.java
in multiple classes in the same directory you can simply use *.java
Examples
COMMAND
DESCRIPTION
javac -sourcepath src Test2.java
Look for source files in src dir in current directory.
javac -sourcepath .;..\src;C:\stuff Test2.java
Look for source files in listed directories.
javac -sourcepath servlet.jar;C:\util.zip Test2.java
Look for source files in listed JAR and ZIP files.
-
-
d
d
Without -d parameter javac creates .class files in current directory ignoring package directive.
Only if -d parameter is used javac will create directory structure as defined with package directive.
Directory structure will be created in directory defined with -d parameter.
.class file will be created in the last directory.
Examples
COMMAND
DESCRIPTION
javac Test.java
Create Test.class in current directory ignoring package directive.
javac -d C:\stuff Test.java
Create directory structure in directory C:\stuff (full Path).
javac -d . Test.java
Create directory structure in current directory.
javac -d classes Test.java
Create directory structure in directory classes in current directory.
javac -d temp\classes Test.java
Create directory structure in directory temp\classes from current directory.
javac -d ..\ Test.java
Create directory structure in parent directory (from current directory).
javac -d ..\classes Test.java
Create directory structure in classes directory inside parent directory
javac -d ..\..\classes Test.java
Create directory structure in directory classes two dirs above current directory.
javac Test.java
Create Test.class in current directory ignoring package directive.
javac -d C:\stuff Test.java
Create directory structure in directory C:\stuff (full Path).
javac -d . Test.java
Create directory structure in current directory.
E
E
x
x
a
a
m
m
p
p
l
l
e
e
This example can be used to test different parameters of javac.exe.
Test.java
package ivoronline.streams;
public class Test {
public static void main(String[] args) {
System.out.println("Hello World.");
}
}
Test2.java
public class Test2 {
public static void main(String[] args) {
Test test = new Test();
test.main(null);
}
}